<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core">

    <script  type="text/javascript" src="media/js/autoNumeric.js"></script>
    <h:outputStylesheet name="grid.css" library="media/css"/>
    
    <div class="section">
        <h:form id="createLot" enctype="multipart/form-data">
            <p:growl autoUpdate="true" />
            <div class="container_24 clearfix">
                <p:panel styleClass="clearfix grid_24 " header="Dados Gerais">

                    <p:outputLabel value="Cadastro:" styleClass="grid_3" />
                    <p:selectOneRadio id="options" value="#{managerEnterprise.multiplyLot}">  
                        <f:selectItem itemLabel="Único" itemValue="#{false}" />  
                        <f:selectItem itemLabel="Vários" itemValue="#{true}" />

                        <p:ajax event="change" update="@form"/>
                    </p:selectOneRadio> 

                    <p:outputLabel  value="#{managerEnterprise.multiplyLot ? 'Nº Inicial:':'Número:'}" styleClass="grid_3" />
                    <p:inputText id="numLot" required="true" value="#{managerEnterprise.lot.num}" 
                                 styleClass="#{managerEnterprise.multiplyLot ? 'grid_10':'grid_20'}" />

                    <p:outputLabel value="Qtd:" 
                                   rendered="#{managerEnterprise.multiplyLot}" styleClass="grid_3" />
                    <p:inputText rendered="#{managerEnterprise.multiplyLot}" 
                                 value="#{managerEnterprise.qtdLot}" styleClass="grid_6" style="width: 26%" />

                  
                    <p:outputLabel value="Quadra Nº:" styleClass="grid_3 blockLabel" />

                    <div class="grid_8" >
                        <p:selectOneMenu id="blockAutocomplete" value="#{managerEnterprise.lot.block}" >  
                            <f:selectItem itemLabel="" itemValue="" />  
                            <f:selectItems value="#{managerEnterprise.selectTypeBlock()}" /> 
                            <p:ajax update="panelDimenssoes, panelValueParcel"  />
                        </p:selectOneMenu> 
                    </div>

                    <p:outputLabel value="Tipo:" styleClass="grid_3" />

                    <p:autoComplete id="typeLotAutocomplete" styleClass="grid_9" dropdown="true" 
                                    converter="typelotconverter"
                                    var="typelotValue" 
                                    itemLabel="#{typelotValue.name.toString().concat(' - R$').concat(typelotValue.value.toString())}" 
                                    itemValue="#{typelotValue}" value="#{managerEnterprise.lot.typeLot}"
                                    scrollHeight="200" forceSelection="true"
                                    completeMethod="#{managerEnterprise.selectTypeLot}" >

                        <p:ajax event="itemSelect" listener="#{managerEnterprise.handleSelect}" 
                                update="tlvalue" />
                    </p:autoComplete>
                </p:panel>
                <div class="clear"/>
                <p:panel id="panelDimenssoes" styleClass="clearfix grid_24 " header="Dimensões">
                    <p:outputLabel value="Variável:" styleClass="grid_3" />
                    <div class="grid_2">
                        <p:selectBooleanCheckbox value="#{managerEnterprise.variable}">
                            <p:ajax update="foreground, background"/>
                        </p:selectBooleanCheckbox>
                    </div>
                    <div class="clear"/>

                    <p:outputLabel value="Frente:" styleClass="grid_3" />
                    <p:inputText id="foreground" styleClass="grid_5" disabled="#{managerEnterprise.variable}" 
                                 value="#{managerEnterprise.variable != true ? managerEnterprise.lot.dimessionX:null}"
                                 onkeypress="jQuery(this).autoNumeric({aSep: '.', aDec: ','} );">
                        <p:ajax event="keyup" update="area, panelValueParcel" listener="#{managerEnterprise.calc()}"/>
                        <f:convertNumber type="number"  locale="pt,BR"   />
                    </p:inputText>

                    <p:outputLabel value="Fundo:" styleClass="grid_3" />
                    <p:inputText id="background" styleClass="grid_5" disabled="#{managerEnterprise.variable}" 
                                 value="#{managerEnterprise.variable != true ? managerEnterprise.lot.dimessionY:null}"
                                 onkeypress="jQuery(this).autoNumeric({aSep: '.', aDec: ','} );">
                        <p:ajax event="keyup" update="area, panelValueParcel" listener="#{managerEnterprise.calc()}"/>
                        <f:convertNumber type="number"  locale="pt,BR"   />
                    </p:inputText>

                    <div class="clear-both"/>

                    <p:outputLabel value="Área (m²):" styleClass="grid_3 blockLabel" />
                    <p:inputText id="area" styleClass="grid_5"  label="Área"
                                 onkeypress="jQuery(this).autoNumeric({aSep: '.', aDec: ',', vMax:'999999999.99'} );"
                                 value="#{managerEnterprise.lot.area}">
                        <f:convertNumber type="number"  locale="pt,BR"   />
                        <p:ajax event="keyup" update="panelValueParcel" listener="#{managerEnterprise.calc()}"/>
                    </p:inputText>

                    <div class="clear-both"/>

                    <p:outputLabel value="Valor / m²:" styleClass="grid_3 blockLabel" />
                    <p:inputText id="tlvalue" styleClass="grid_5" readonly="true" 
                                 value="#{managerEnterprise.lot.typeLot.value}"/>

                </p:panel>
                <div class="clear"/>
                
                <p:panel id="panelValueParcel" styleClass="clearfix grid_24 " header="Valores">
                    <p:outputLabel value="A vista:" styleClass="grid_3" />
                    <p:inputText  styleClass="grid_8" readonly="true" value="#{managerEnterprise.lot.sees}"
                                  onkeypress="jQuery(this).autoNumeric({aSign: 'R$', aSep: '.', aDec: ','} );">
                        <f:convertNumber type="currency"  locale="pt,BR"  />
                    </p:inputText>

                    <p:outputLabel value="Entrada (%): " styleClass="grid_4" />
                    <p:inputText styleClass="grid_8" readonly="true" value="#{managerEnterprise.lot.sees * managerEnterprise.enterprise.porcBegin}"
                                 onkeypress="jQuery(this).autoNumeric({aSign: 'R$', aSep: '.', aDec: ','} );">
                        <f:convertNumber type="currency"  locale="pt,BR"  />
                    </p:inputText>

                    <div class="clear"/>

                    <p:dataTable id="tableInterest"  styleClass="grid_24"
                                 var="interestValue"
                                 rowIndexVar="idInterest"
                                 emptyMessage="Nenhum registro"
                                 value="#{managerEnterprise.interestParcels}">  
                        <f:facet name="header">
                            Pagamento Parcelado
                        </f:facet>
                        <p:column headerText="Quantidade de Parcelas"> 
                            #{interestValue.qtd}
                        </p:column>  
                        <p:column headerText="Valor por Parcela">  
                            <h:outputLabel value="R$ #{managerEnterprise.calcJuros(interestValue.qtd, interestValue.porc)}">
                                <f:convertNumber pattern="#,###,##0.00"/>
                            </h:outputLabel>
                        </p:column> 
                    </p:dataTable> 
                </p:panel>
                <div class="double-line" />
                <div class="buttonAction">
                    <p:commandButton value="Adicionar Lote" process="@form" update="@form, :tabView:formResume" 
                                     actionListener="#{managerEnterprise.addLot()}"  
                                     icon="ui-icon-plus" styleClass="ui-priority-primary"/>

                    <p:commandButton value="Limpar" process="@form" update="@form" 
                                     oncomplete="dlg.show()"
                                     icon="ui-icon-disk" />
                </div>
               

                
            </div>

            <p:dialog header="Cadastro realizado com sucesso!" widgetVar="dlg" modal="true"
                      showEffect="fade" hideEffect="fade" resizable="false" height="70">  
                <h:outputText value="Deseja ir para a área de cadastro de lote ?" /> <br/> 
                <f:facet name="footer">
                    <center>
                        <p:commandButton value="Sim" icon="ui-icon-check" 
                                         update="@form"  />
                        <p:commandButton value="Não, depois" onclick="dlg.hide()" icon="ui-icon-close" />
                    </center>
                </f:facet>

            </p:dialog>
        </h:form>
        
    </div>
</ui:composition>
